<style type="text/css">
.qrcode-login-box{ text-align: center; width: 280px; height: 240px; overflow: hidden; }
.qrcode-login-box .desc{ line-height: 30px; }
.qrcode-login-box .switch{ position: absolute; right: 0; bottom: 0; height: 50px; width: 50px; background-repeat: no-repeat !important; background-position: right bottom !important; background-size: 100% !important; cursor: pointer; }
.qrcode-login-box .pc-login{ background: url(/public/images/icon-pc-login-bottom.png); }
.qrcode-login-box .weixin-login{ background: url(/public/images/icon-qrcode-login-bottom.png); }
.weixin-login-box{ }
.pc-login-box { margin-top: 20px; display: none; }
</style>
<div class="qrcode-login-box">
	<div class="weixin-login-box">
		<div class="qrcode">
			<img src="{:url('weixin_login_qrcode')}" width="200" height="200">
		</div>
		<div class="desc">微信扫描二维码{$type == 'login' ? '登录' : '快速注册'}</div>
	</div>
	<div class="pc-login-box">
		<form class="login-form" action="{:url('index')}" method="post">
			<div class="form-group text-center text-muted"><h4>账号登录</h4></div>
			<div class="form-group">
				<input class="form-control" type="text" name="username" placeholder="手机号码" autocomplete="off"/>
			</div>
			<div class="form-group">
				<input class="form-control" type="password" name="password" placeholder="密码" />
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-primary">立即登录</button>
			</div>
		</form>
	</div>
	<eq name="type" value="login">
		<div class="switch pc-login"></div>
	</eq>
</div>

<script type="text/javascript">
var weixin_status;
$(document).ready(function () {
	// 密码MD5加密
	$('form.login-form').on('submit', function () {
		$('input[type="password"]').each(function () {
			if(!$(this).hasClass('not-md5') && $(this).val()){
				var password     = $(this).val();
				var password_md5 = $.md5(password);
				$(this).val(password_md5);
			}
		});
	});
	$('.qrcode-login-box .switch').click(function () {
		if($(this).hasClass('pc-login')){
			$(this).removeClass('pc-login').addClass('weixin-login');
			$('.pc-login-box').show();
			$('.weixin-login-box').hide();
			window.clearTimeout(weixin_status);
		}else{
			$('.pc-login-box').hide();
			$('.weixin-login-box').show();
			$(this).removeClass('weixin-login').addClass('pc-login');
			weixin_login_status(1);
		}
	});
	$('.remove-win').click(function () {
		window.clearTimeout(weixin_status);
	})
	weixin_login_status(1);
});
function weixin_login_status(time) {
	$.ajax({
		type: "get",
		url: "{:url('weixin_login_status')}",
		dataType:"json",
		success: function(data){
			if(data.code == 1){
				msgbox(data.msg);
				if(data.url){
					jumpurl(data.url);
				}
			}else{
				if(data.data.is_tips){
					msgbox(data.msg, 'error', '', 5);
					if(data.url){
						jumpurl(data.url);
					}
				}
			}
		},
		error :function (data) {
			msgbox('请求失败，请稍候再试！', 'error');
		}
	});
	var time = time ? time : 3;
	weixin_status = setTimeout("weixin_login_status(" + time + ")", time * 1000);
}
</script>